package util

import (
	"encoding/hex"
	"github.com/tjfoc/gmsm/sm3"
	"short-link/model"
)

func GenerateMd5(str string) string {
	h := sm3.New()
	h.Write([]byte(model.AppConfig.Secret.DigestPrefix + str + model.AppConfig.Secret.DigestSuffix))
	return hex.EncodeToString(h.Sum(nil))
}

const base62 = "TabE2FghstxG13ijqkpr4JKLPAzOQ5dCeBHRScfMINVuW6lmDynoUXv7wY8Z90"

func Base62Encode(num int64) string {
	var result string
	var l = int64(len(base62))
	for num > 0 {
		result = string(base62[num%l]) + result
		num /= l
	}
	return result
}

func SaveWrapPath(path string) string {
	for len(path) < 6 {
		path = "0" + path
	}
	return path
}
